/*!
\copyright  Copyright (c) 2022 Qualcomm Technologies International, Ltd.\n
            All Rights Reserved.\n
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      LE state machine handler interfaces.
*/

#ifndef SINK_SERVICE_LE_SM_H_
#define SINK_SERVICE_LE_SM_H_

#ifdef ENABLE_LE_SINK_SERVICE

#include <device.h>
#include <message.h>
#include <bdaddr.h>
#include <connection_manager.h>
#include "sink_service_protected.h"


/*! \brief Register for GATT Notifications
*/
void SinkServiceLeSm_RegisterForGattNotifications(void);

/*! \brief Clear the data for an SM instance and reset it

    \param sm The SM to reset
*/
void SinkServiceLeSm_ClearInstance(sink_service_state_machine_t *sm);

/*! \brief Request a SM instance attempts to connect to a device
           If there is no suitable device in the device list then pairing will begin
           If there is an MRU that will be used. If no MRU then the first sink device
           in the device list will be used.

    \param sm The SM to connect
    \return TRUE if the request was successfully made
*/
bool SinkServiceLeSm_ConnectRequest(sink_service_state_machine_t *sm);

/*! \brief Request a SM instance to pair to a new device
           This will start LE RSSI pairing to search for an suitable candidate

    \param sm The SM to start pairing on
    \return TRUE if the request was successfully made
*/
bool SinkServiceLeSm_PairRequest(sink_service_state_machine_t *sm);

/*! \brief Request a SM instance attempts to disconnect all profiles from its device.
           This function will disconnect all configured profiles from the SM device

    \param sm The SM to disconnect
    \return TRUE if the request was successfully made
*/
bool SinkServiceLeSm_DisconnectRequest(sink_service_state_machine_t *sm);

/*! \brief Have max supported LE connections been established?

    \return TRUE if max LE connections reached, otherwise FALSE
*/
bool SinkServiceLeSm_MaxLeAclConnectionsReached(void);

/*! \brief Get the number of LE ACL connections
    \return Number of LE ACL connections.
*/
unsigned SinkServiceLeSm_GetLeAclConnectionCount(void);

/*! \brief Set a device for the SM instance

    \param sm The SM set the device for
    \param device The device to set
*/
void SinkServiceLeSm_SetDevice(sink_service_state_machine_t *sm, device_t device);

/*! \brief Create a new instance of a sink state machine.

    This will return NULL if a new state machine cannot be created,
    for example if the maximum number of sinks already exists.

    \param device Device to create state machine for.

    \return Pointer to new state machine, or NULL if it couldn't be created.
*/
sink_service_state_machine_t *SinkServiceLeSm_CreateSm(device_t device);

/*! \brief Try to find an active sink state machine for a device_t.

    \param device Device to search for.
    \return Pointer to the matching state machine, or NULL if no match.
*/
sink_service_state_machine_t *SinkServiceLeSm_GetSmForDevice(device_t device);

/*! \brief Try to find an active LE sink state machine for an address.

    \param[in] addr LE address to search for.

    \return Pointer to the matching state machine, or NULL if no match.
*/
sink_service_state_machine_t *SinkServiceLeSm_GetSmFromTpaddr(tp_bdaddr *addr);

/*! \brief Transition the Sink Service State Machine from DISCONNECTED to DISABLED */
void SinkServiceLeSm_DisableAll(void);

/*! \brief Transition the Sink Service State Machine from DISABLED to DISCONNECTED */
void SinkServiceLeSm_EnableAll(void);

#endif /* ENABLE_LE_SINK_SERVICE */

#endif /* SINK_SERVICE_LE_SM_H_ */

